<?php
require_once("inc.member.php");

$this_title="$vars[title] &raquo; ".__("Genealogy");
$page_title=__("Genealogy");
$content_title=__("Genealogy");

$r_status=array("normal","unverified","suspended","terminated");
$r_status_d=array("normal"=>__("Normal"),"unverified"=>__("Unverified"),"suspended"=>__("Suspended"),"terminated"=>__("Terminated"));

require_once('inc.genealogy_tab.php');

$this_month['start'] = date('Y-m-d H:i:s', mktime(0,0,0,ndate('n'),1,ndate('Y')));
$this_month['end'] = date('Y-m-d H:i:s', mktime(23,59,59,ndate('n')+1,0,ndate('Y')));

//##### AJAX CALL #####
//downline child request
if($get_s['aj'] && $_GET["gen_tree"]){
	$user = get_user_detail_by_id($get_d['id']);
	if($user){		
		$downline_node = retrieve_gen_downline($user['id'], 'ref', 'gen_tree', 2);
	}
	print $downline_node;
	exit;
}
//##### END AJAX CALL #####

//#####GET DOWNLINE
$r_upline=$r_user;
$upline_id=$uid;
$which_network = 'ref';
if($_GET['cur_uid']!=""){	
	$upline_code = $_GET['cur_uid'];	
	$r_upline=get_user_detail_by_code($upline_code);	
	if(!$r_upline || !is_group_ref_downline_of($r_upline["id"], $uid)){		
		//$r_upline=0;
		$upline_id=$uid;	
	}else{
		$upline_id=$r_upline["id"];
	}
} 
$downline_node = retrieve_gen_downline($upline_id, 'ref', 'gen_tree', 2);

$head = $r_upline;
if($head["acc_type"]=="c"){
	$display_pic=JS_URL."/jqtree/images/node{$head[acc_type]}.gif";
}elseif($head["gender"]=="m"){
	$display_pic=JS_URL."/jqtree/images/node{$head[gender]}.gif";
}else{
	$display_pic=JS_URL."/tree/images/nodef.gif";
}
//ps
$this_month_sales_maintain = calc_personal_sales($head['id'], $this_month['start'], $this_month['end']);
$strlen = strlen($head['name']);
$head_width=$vars['gen_tweak']['base_info_width'] + ($strlen * ($vars['gen_tweak']['char_width']) + 10) + 100;
if($upline_id>0){
$head_node = "<span class='gen_img'><img src='$display_pic' /></span> <span class='gen_id'>".$head["code"]."</span>".
"<span class='gen_jdate'>Joined ".date($vars['date_format'], strtotime($head["cdate"]))."</span>".
" <span class='gen_pspgs'>".__($vars['rank_index_a_d'][$head["rank_a"]])."</span>";}
$downline_tree=__("Go to the network of member ID:")."
<select name='cur_uid' id='cur_uid' onchange=\"window.location='$this_file?cur_uid='+document.getElementById('cur_uid').value;\" >".get_sponsor_downline($uid, $_GET['cur_uid'])."</select></p>"."
<div id='genealogy_tree' class='tree'>
 <ul>
  <li class='root' id='0' style='width:{$head_width}px;'><div class='tree-node".(USER_BROWSER == 'msie'? "-ie" : '')."'>$head_node</div><div class='clear'></div>
   <ul>
	$downline_node
   </ul>
  </li>
 </ul>
</div>";

$downline_box=
"<p class='bold'>".replace_tag(__("Genealogy for your Account ID: <%uid%>, Name: <%name%>."), array("<%uid%>"=>$r_user['code'], "<%name%>"=>$r_user['name']))."</p>
<div class='genealogy'>
	$downline_tree
</div>";

ob_start();
?>
<script type='text/javascript' src='<?php echo JS_URL."/get_file_gzip.php?file=".urlencode("jquery.js,jquery.livequery.js,jqtree/tree.js"); ?>'></script>
<script type='text/javascript'>
jQuery(document).ready(function(j){
	j('#genealogy_tree').SimpleTree({animate: true});
});
</script>
<link rel='stylesheet' href='<?php echo JS_URL; ?>/jqtree/style.css' type='text/css'>
<?php
$jvscript = ob_get_clean();

$content="<h2>$page_title</h2>".$downline_box;
$content=str_replace("<%tab_content%>", $content, $tab);

print format_member_page($content, $this_title, $content_title, $css . $jvscript);
?>